package com.timesheet.gui.efforttracker.controllers;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.DateTime;

import com.example.timesheet.uitl.DateUtil;
import com.timesheet.gui.efforttracker.composite.LeaveSearchComposite;
import com.timesheet.gui.efforttracker.container.LeaveModelContainer;
import com.timesheet.gui.efforttracker.container.UtilisationModelContainer;
import com.timesheet.server.common.models.EffortTrackerDTO;
import com.timesheet.server.common.session.Session;
import com.timesheet.serverice.LeaveService;

public class LeaveSearchCompositeController {

	
	private LeaveSearchComposite leaveSearchComposite = null ;

	public LeaveSearchCompositeController(LeaveSearchComposite leaveSearchComposite) {
		this.leaveSearchComposite = leaveSearchComposite ;
		init();
		performActions(leaveSearchComposite);
	}

	private void init() {
		
		
	}

	void performActions(LeaveSearchComposite wsrDateChooseComposite) {
		wsrDateChooseComposite.getBtnSubmit().addSelectionListener(
				new SelectionAdapter() {

					@Override
					public void widgetSelected(SelectionEvent e) {
						save();
					}

				});
	}

	private void save() {
		System.out.println("Leave search composite controller save");		
		DateTime dtFrom = leaveSearchComposite.getDtFrom();
		Calendar calFrom = DateUtil.createDate3(dtFrom.getDay(), dtFrom.getMonth(), dtFrom.getYear());
		System.out.println(calFrom.getTime());
		DateTime dtTo = leaveSearchComposite.getDateTo();
		Calendar calTo = DateUtil.createDate3(dtTo.getDay(), dtTo.getMonth(), dtTo.getYear());	
		System.out.println(calTo.getTime());
		List<EffortTrackerDTO> myLeaves = new LeaveService().getAllLeaves(calFrom.getTime(), calTo.getTime(), Session.INSTANCE.getUser());
		System.out.println(myLeaves);		
		LeaveModelContainer leaveModelContainer = LeaveModelContainer.getInstance();
		leaveModelContainer.setMyLeaves(myLeaves);
		leaveModelContainer.refresh();

	}



	
}
